package intelligentCustomer.planning;

import dev.langchain4j.model.openai.OpenAiStreamingChatModel;

/**
 * 搜索步骤
 * 搜索相关信息
 */
public class SearchStep implements PlanStep {
    private final String name;
    private final OpenAiStreamingChatModel model;
    private int searchScope = 1; // 搜索范围，用于调整
    
    public SearchStep(String name, OpenAiStreamingChatModel model) {
        this.name = name;
        this.model = model;
    }
    
    @Override
    public String execute(PlanningContext context) {
        // 获取前一步的分析结果
        String analysis = context.getResult("需求分析");
        
        String prompt = String.format(
            "基于以下需求分析，搜索相关信息。搜索范围：%d\n" +
            "需求分析：%s\n" +
            "原始查询：%s\n" +
            "请提供最相关的搜索结果。",
            searchScope,
            analysis != null ? analysis : "未提供",
            context.getQuery()
        );
        
        return ReasonGenerator.generate(model, prompt);
    }
    
    @Override
    public String getName() {
        return name;
    }
    
    @Override
    public void adjustParameters(PlanningContext context) {
        // 根据重试次数扩大搜索范围
        searchScope = Math.min(3, searchScope + 1);
    }
} 